//
//  SISSMyKPICell.m
//  SISSAPP
//
//  Created by 袁应荣 on 2018/10/16.
//  Copyright © 2018年 优房网. All rights reserved.
//

#import "SISSMyKPICell.h"

@interface SISSMyKPICell ()

/// 申报日期
@property (weak, nonatomic) UILabel *applyDateLabel;
/// 支付日期
@property (weak, nonatomic) UILabel *checkStatusLabel;
/// {小区}{楼栋}{房号}
@property (weak, nonatomic) UILabel *houseLabel;
/// 业务类型
@property (weak, nonatomic) UILabel *businessTypeTitleLabel;
@property (weak, nonatomic) UILabel *businessTypeLabel;
/// 分值
@property (weak, nonatomic) UILabel *scoreTitleLabel;
@property (weak, nonatomic) UILabel *scoreLabel;
@property (weak, nonatomic) UIButton *button;

@property (weak, nonatomic) UIView *bottomLine;

@end
@implementation SISSMyKPICell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setAchievementListModel:(SISSAchievementListModel *)achievementListModel {
    _achievementListModel = achievementListModel;
    
    self.applyDateLabel.text = (achievementListModel.insert_time && achievementListModel.insert_time.length > 10) ? [achievementListModel.insert_time substringToIndex:10] : @"";
    NSString *businessState = @"";
    if ([achievementListModel.business_state isEqualToString:@"0"]) {
        businessState = @"未审批";
    } else if ([achievementListModel.business_state isEqualToString:@"1"]) {
        businessState = @"已审批";
    } else if ([achievementListModel.business_state isEqualToString:@"2"]) {
        businessState = @"已否认";
    }
    self.checkStatusLabel.text = businessState;
    self.houseLabel.text = [NSString stringWithFormat:@"%@ %@ %@",achievementListModel.neighbourhood ? achievementListModel.neighbourhood : @"",achievementListModel.b_num ? achievementListModel.b_num : @"",achievementListModel.d_num ? achievementListModel.d_num : @""];
    self.businessTypeLabel.text = achievementListModel.business_type;
    self.scoreLabel.text = [NSString stringWithFormat:@"%@套",[PublicUtil returnTwoDeciTwoDecimalFormatter:achievementListModel.achievement_value]];
}

- (void)buttonClickAction {
    UIResponder *responder = self;
    UIViewController *viewController;
    while ((responder = [responder nextResponder])){
        if ([responder isKindOfClass: [UIViewController class]]) {
            viewController = (UIViewController *)responder;
            break;
        }
    }
    [viewController alertActionAlertWithTitle:@"分值计算方式" message:@"套数=售单+租单*0.76*份额占比；\n住宅（含公寓）=1.34*非住宅*份额占比；\n占比份额由机构确定；" confirmTitle:@"关闭"];
}

- (void)initUI {
    [super initUI];
    
    /// 申报日期
    UILabel *applyDateLabel = [UILabel yyr_labelWithText:@"{申报日期}" fontSize:15 textColor:MAIN_TEXT_COLOR];
    [self.contentView addSubview:applyDateLabel];
    self.applyDateLabel = applyDateLabel;
    
    /// 审核状态
    UILabel *checkStatusLabel = [UILabel yyr_labelWithText:@"{审核状态}" fontSize:15 textColor:MAIN_TEXT_COLOR];
    [self.contentView addSubview:checkStatusLabel];
    self.checkStatusLabel = checkStatusLabel;
    
    /// {小区}{楼栋}{房号}
    UILabel *houseLabel = [UILabel yyr_labelWithText:@"{小区}{楼栋}{房号}" fontSize:15 textColor:MAIN_TEXT_COLOR];
    [self.contentView addSubview:houseLabel];
    self.houseLabel = houseLabel;
    
    /// 业务类型
    UILabel *businessTypeTitleLabel = [UILabel yyr_labelWithText:@"业务类型：" fontSize:15 textColor:MAIN_TEXT_COLOR];
    [self.contentView addSubview:businessTypeTitleLabel];
    self.businessTypeTitleLabel = businessTypeTitleLabel;
    
    UILabel *businessTypeLabel = [UILabel yyr_labelWithText:@" " fontSize:15 textColor:MAIN_TEXT_COLOR];
    [self.contentView addSubview:businessTypeLabel];
    self.businessTypeLabel = businessTypeLabel;
    
    /// 业绩值
    UILabel *scoreTitleLabel = [UILabel yyr_labelWithText:@"业绩值：" fontSize:15 textColor:MAIN_TEXT_COLOR];
    [self.contentView addSubview:scoreTitleLabel];
    self.scoreTitleLabel = scoreTitleLabel;
    
    UILabel *scoreLabel = [UILabel yyr_labelWithText:@"3" fontSize:15 textColor:MAIN_TEXT_COLOR];
    [self.contentView addSubview:scoreLabel];
    self.scoreLabel = scoreLabel;
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setImage:[UIImage imageNamed:@"?-anz"] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(buttonClickAction) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:button];
    self.button = button;
    
    UIView *bottomLine = [[UIView alloc] init];
    bottomLine.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [self.contentView addSubview:bottomLine];
    self.bottomLine = bottomLine;
}

- (void)initConstraint {
    [super initConstraint];
    
    CGFloat margin = 8.0;
    CGSize buttonSize = CGSizeMake(16, 16);
    WeakSelf
    [self.applyDateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(weakSelf.contentView).offset(2 * margin);
    }];
    
    [self.checkStatusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(weakSelf.contentView).offset(-2 * margin);
        make.top.equalTo(weakSelf.applyDateLabel);
    }];
    
    [self.houseLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.applyDateLabel);
        make.top.equalTo(weakSelf.applyDateLabel.mas_bottom).offset(2 * margin);
    }];
    
    [self.businessTypeTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.applyDateLabel);
        make.top.equalTo(weakSelf.houseLabel.mas_bottom).offset(2 * margin);
    }];
    
    [self.businessTypeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.businessTypeTitleLabel);
        make.left.equalTo(weakSelf.businessTypeTitleLabel.mas_right);
        make.right.equalTo(weakSelf.contentView).offset(-2 * margin);
    }];
    
    [self.scoreTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.businessTypeTitleLabel);
        make.top.equalTo(weakSelf.businessTypeTitleLabel.mas_bottom).offset(2 * margin);
    }];
    [self.scoreLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.scoreTitleLabel);
        make.left.equalTo(weakSelf.scoreTitleLabel.mas_right);
    }];
    [self.button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.scoreLabel.mas_right).offset(2 * margin);
        make.centerY.equalTo(weakSelf.scoreTitleLabel);
        make.size.mas_equalTo(buttonSize);
    }];
    
    [self.bottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.scoreTitleLabel.mas_bottom).offset(2 * margin);
        make.left.bottom.right.equalTo(weakSelf.contentView);
        make.height.mas_equalTo(1);
    }];
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
